package com.yupi.springbootinit.bizmq;


import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class MyMessageConsumer {

    /**
     * 接受消息的方法
     * */
    // 简化异常处理
    @SneakyThrows
    // 使用
    @RabbitListener(queues = "code_queue", ackMode = "MANUAL")
    public void  receiveMessage(String message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag){
        // 使用日志打印接收到的消息内容
        log.info("接收到消息：{}",message);
        channel.basicAck(deliveryTag,false);
    }
}
